package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 卡尼奶
 * @Date 2022/5/18 8:57
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {


    @Autowired
    private BaseAttrInfoService attrInfoService;

    /**
     * 根据分类id获取平台属性
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(
            @PathVariable("category1Id")Long category1Id,
            @PathVariable("category2Id")Long category2Id,
            @PathVariable("category3Id")Long category3Id){
        List<BaseAttrInfo> attrInfos = attrInfoService.getAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfos);
    }

    /**
     * 保存或修改属性信息
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveOrUpdateAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        attrInfoService.saveOrUpdateAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId")Long attrId){
       List<BaseAttrValue> attrValues = attrInfoService.getAttrValueList(attrId);
       return Result.ok(attrValues);
    }
}
